package com.reset.password.result;

import lombok.ToString;

@ToString
public enum ResultCode {
    SUCCESS(200, "成功","/manual?code=0"),
    ERROR(-1, "错误","/manual?code=-1"),
    BAD_REQUEST(400, "请求错误","/manual?code=400"),
    UNAUTHORIZED(401, "未授权","/manual?code=401"),
    FORBIDDEN(403, "禁止访问","/manual?code=403"),
    NOT_FOUND(404, "资源未找到","/manual?code=404"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误","/manual?code=500"),
    // 参数相关
    PARAMETER_ERROR(4001, "参数错误","/manual?code=4001"),
    // 文件上传相关
    FILE_EMPTY(5001, "文件为空，请选择文件后重试","/manual?code=5001"),
    //上传相关 上传失败
    UPLOAD_FAIL(5002, "上传失败，请联系管理员","/manual?code=5002"),
    // 认证中心相关
    NOT_LOGIN(8001, "未登录","/manual?code=8001"),
    INVALID_TOKEN(8002, "无效的token","/manual?code=8002");




    private final int code;
    private final String message;
    private final String url;

    ResultCode(int code, String message,String url) {
        this.code = code;
        this.message = message;
        this.url = url;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    /**
     * 通过code获取枚举的静态方法
     */
    public static String getEnumByCode(int code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode() == code) {
                return resultCode.toString();
            }
        }
        return "未查到对应解决方案";
    }
}
